#ifndef FLOATINGWIDGETTITLEBAR_H
#define FLOATINGWIDGETTITLEBAR_H
/*******************************************************************************
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/


//============================================================================
/// \file   FloatingWidgetTitleBar.h
/// \author Uwe Kindler
/// \date   13.05.2019
/// \brief  Declaration of CFloatingWidgetTitleBar class
//============================================================================

//============================================================================
//                                   INCLUDES
//============================================================================
#include <QFrame>
#include <QIcon>

namespace ads
{
class CFloatingDockContainer;

struct FloatingWidgetTitleBarPrivate;


/**
 * 浮动窗口部件的标题栏，用于捕获非客户区鼠标事件。
 * Linux不支持NonClientArea的鼠标事件，如QEvent::NonClientAreaMouseButtonPress。
 * 由于这些事件对于正确工作的停靠系统是必需的，因此我们在这里使用自己的标题栏来捕获所需的鼠标事件。
 */
class CFloatingWidgetTitleBar : public QFrame
{
    Q_OBJECT
    Q_PROPERTY(QIcon maximizeIcon READ maximizeIcon WRITE setMaximizeIcon)
    Q_PROPERTY(QIcon normalIcon READ normalIcon WRITE setNormalIcon)

private:
    FloatingWidgetTitleBarPrivate *d; ///< 私有数据 (pimpl)

protected:
    // 重写鼠标事件函数
    virtual void mousePressEvent(QMouseEvent *ev) override;
    virtual void mouseReleaseEvent(QMouseEvent *ev) override;
    virtual void mouseMoveEvent(QMouseEvent *ev) override;
    virtual void mouseDoubleClickEvent(QMouseEvent *event) override;

    // 属性函数
    void setMaximizeIcon(const QIcon& Icon);
    QIcon maximizeIcon() const;
    void setNormalIcon(const QIcon& Icon);
    QIcon normalIcon() const;

public:
    using Super = QWidget;

    // 构造函数
    explicit CFloatingWidgetTitleBar(CFloatingDockContainer *parent = nullptr);

    // 虚析构函数
    virtual ~CFloatingWidgetTitleBar();

    // 启用/禁用窗口关闭按钮
    void enableCloseButton(bool Enable);

    // 设置窗口标题
    void setTitle(const QString &Text);

    // 更新样式表样式
    void updateStyle();

    // 根据当前窗口状态更改最大化按钮图标
    void setMaximizedIcon(bool maximized);

signals:
    // 关闭按钮点击时发出的信号
    void closeRequested();

    // 最大化按钮点击时发出的信号
    void maximizeRequested();
};
} // namespace ads
#endif // FLOATINGWIDGETTITLEBAR_H
